<?php

class producten
{
	function get_productinfo()
		{
			echo"<form method='GET' action='productopvragen.php'>
			Productid : <input type='text' name='id' size='7'/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<input type='submit' value='Productinfo opvragen'/>
			</form><br />
			<form method='POST' action='productwijzigen.php'>
			<input type='submit' value='Nieuw product aanmaken'/>
			</form>	";
		}
		
		function vraag_product()
		{
			if(!isset($_POST['Wijzigen']))
			{
			$p_id = $_GET['id'];
			$hulp = '0';
			$product_info = mysql_query("SELECT Productid, Naam, Prijs, cat1, cat2, UnitOmschrijving, CoreOmschrijving, Gewicht FROM producten WHERE Productid = $p_id") or die(mysql_error());
			}
			if(isset($_POST['Wijzigen']))
			{
				$id = $_POST['p_id'];
				$naam = $_POST['p_naam'];
				$prijs = $_POST['p_prijs'];
				$cat1 = $_POST['p_cat1'];
				$cat2 = $_POST['p_cat2'];
				$unit = $_POST['p_unit'];
				$core = $_POST['p_core'];
				$gewicht = $_POST['p_gewicht'];
				$hulp = '1';
				$update_product = mysql_query("UPDATE producten SET Naam = '$naam',
																	Productid = '$id',
																	Prijs = '$prijs',
																	cat1 = '$cat1',
																	cat2 = '$cat2',
																	UnitOmschrijving = '$unit',
																	CoreOmschrijving = '$core',
																	Gewicht = '$gewicht' WHERE Productid = $id") or die(mysql_error());
				$product_info = mysql_query("SELECT Productid, Naam, Prijs, cat1, cat2, UnitOmschrijving, CoreOmschrijving, Gewicht FROM producten WHERE Productid = $id") or die(mysql_error());
			}
			
			while($product_row = mysql_fetch_array($product_info))
			{
				$naam = $product_row['Naam'];
				$id = $product_row['Productid'];
				$prijs = $product_row['Prijs'];
				$cat1 = $product_row['cat1'];
				$cat2 = $product_row['cat2'];
				$unit = $product_row['UnitOmschrijving'];
				$core = $product_row['CoreOmschrijving'];
				$gewicht = $product_row['Gewicht'];
				
				if($hulp == '1')
				{
					echo"Het product is gewijzigd!<hr>";
				}
	
				echo "<form method = 'POST' action='".$_SERVER['PHP_SELF']."'>
				Product naam: <input type='text' name='p_naam' value='$naam' size='25'/>
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				Product id: <input type='text' name='p_id' value='$id' size='10'/><br><br>
				Product prijs: <input type='text' name='p_prijs' value='$prijs' size='10'/><br><br>
				Product categorie 1: <input type='text' name='p_cat1' value='$cat1' size='12'/>
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				Product categorie 2: <input type='text' name='p_cat2' value='$cat2' size='12'/><br><br>
				Unit omschrijving: <br><textarea rows='1' cols='40' name='p_unit'>".$product_row['UnitOmschrijving']."</textarea><br><br>
				Core omschrijving: <br><textarea rows='5' cols='40' name='p_core'>".$product_row['CoreOmschrijving']."</textarea><br><br>
				Gewicht: <input type='text' name='p_gewicht' value='$gewicht' size='10'/>
				<center><input type='submit' name='Wijzigen' value='Wijzig!'/>&nbsp;&nbsp;&nbsp;&nbsp;
				<a href='productinfo.php'><input type='reset' name='terug' value='Ga terug!'/></a></center>
				</form>";
			}
		}
		
		function nieuw_product()
		{
			if(isset($_POST['Wijzigen']))
			{
				$id = $_POST['p_id'];
				$naam = $_POST['p_naam'];
				$prijs = $_POST['p_prijs'];
				$cat1 = $_POST['p_cat1'];
				$cat2 = $_POST['p_cat2'];
				$unit = $_POST['p_unit'];
				$core = $_POST['p_core'];
				$gewicht = $_POST['p_gewicht'];
				$hulp = '1';
				$update_product = mysql_query("INSERT INTO producten(`Naam`, `Productid`, `Prijs`, `cat1`, `cat2`, `UnitOmschrijving`, `CoreOmschrijving`, `Gewicht`) 
												VALUES('$naam', '$id', '$prijs', '$cat1', '$cat2', '$unit', '$core', '$gewicht')") or die(mysql_error());
			}
			
			
			echo "<form method = 'POST' action='".$_SERVER['PHP_SELF']."'>
				Product naam: <input type='text' name='p_naam' size='25'/>
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				Product id: <input type='text' name='p_id' size='10'/><br><br>
				Product prijs: <input type='text' name='p_prijs' size='10'/><br><br>
				Product categorie 1: <input type='text' name='p_cat1' size='12'/>
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				Product categorie 2: <input type='text' name='p_cat2' size='12'/><br><br>
				Unit omschrijving: <br><textarea rows='1' cols='40' name='p_unit'></textarea><br><br>
				Core omschrijving: <br><textarea rows='5' cols='40' name='p_core'></textarea><br><br>
				Gewicht: <input type='text' name='p_gewicht' size='10'/><br><br>
				<center><input type='submit' name='Wijzigen' value='Voeg toe!'/>&nbsp;&nbsp;&nbsp;&nbsp;
				<a href='productinfo.php'><input type='reset' name='terug' value='Ga terug!'/></a></center>
				</form>";
			}
}
?>